//
//  HightStoreTopView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/9.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "HightStoreTopView.h"
//#import "HightSearchViewButton.h"
#import "SearchBarView.h"

@interface HightStoreTopView ()<UISearchBarDelegate>
{
    NSString * sectron_Text;
}
@end

@implementation HightStoreTopView

-(id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView{
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        //
//        HightSearchViewButton * searchBut = [[HightSearchViewButton alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(36), kHeightProportion_In_iPhoneTriploid(7), KScreenWidth- kWidthProportion_In_iPhoneTriploid(72), kHeightProportion_In_iPhoneTriploid(30)) inSuperView:self];
//        searchBut.layer.masksToBounds = YES;
//        searchBut.layer.cornerRadius = kHeightProportion_In_iPhoneTriploid(15);
//        searchBut.backgroundColor = [UIColor whiteColor];
        SearchBarView * searchView = [[SearchBarView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(35), kHeightProportion_In_iPhoneTriploid(7), KScreenWidth - kWidthProportion_In_iPhoneTriploid(70), kHeightProportion_In_iPhoneTriploid(30))];
        searchView.layer.cornerRadius = kHeightProportion_In_iPhoneTriploid(15);
        searchView.layer.masksToBounds = YES;
        searchView.backgroundColor = [UIColor whiteColor];
        searchView.delegate = self;
        //光标颜色
        searchView.cursorColor = [UIColor blackColor];
        //清除按钮图标
        searchView.clearButtonImage = [UIImage imageNamed:@"qingchu"];
        searchView.searchBarTextField.backgroundColor = [UIColor whiteColor];
        searchView.searchBarTextField.font = [UIFont systemFontOfSize:14];
        //输入框提示
        NSString *holderText = @"输入品名/材质/规格/店铺名";
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
        [placeholder addAttribute:NSForegroundColorAttributeName
                            value:[UIColor colorWithHexString:@"#999999"]
                            range:NSMakeRange(0, holderText.length)];
        [placeholder addAttribute:NSFontAttributeName
                            value:[UIFont systemFontOfSize:14]
                            range:NSMakeRange(0, holderText.length)];
        searchView.searchBarTextField.attributedPlaceholder = placeholder;
        //去掉取消按钮灰色背景
        searchView.hideSearchBarBackgroundImage = YES;
        [self addSubview:searchView];
    }
    return self;
}

#pragma mark - UISearchBar Delegate
- (CGSize)intrinsicContentSize {
    return UILayoutFittingExpandedSize;
}
//已经开始编辑时的回调
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
//    if (self.delegate && [self.delegate respondsToSelector:@selector(beginAction)]) {
//        [self.delegate beginAction];
//    }
}

//编辑文字改变的回调
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    DLog(@"searchText:%@",searchText);
    sectron_Text = searchText;
//    if (self.delegate && [self.delegate respondsToSelector:@selector(secrechActionText:theType:)]) {
//        [self.delegate secrechActionText:sectron_Text theType:2];
//    }
}

//搜索按钮
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {//DLog(@"搜索");//
    kKeyboardEndEditing
    if (self.Block_SearchStr) {
        self.Block_SearchStr(sectron_Text);
    }
}

@end
